#include "pch.h"

UniformNearFarUpdateCallback::UniformNearFarUpdateCallback(osg::Camera * camera) :
	mCamera(camera)
	, m_bFirstTime(true)
{

}

void UniformNearFarUpdateCallback::operator()(osg::Uniform* uniform, osg::NodeVisitor* nv) 
{
	
	//osg::Matrix projectM = mCamera->getProjectionMatrix();
	//uniform->set(projectM);

	if(m_bFirstTime)
	{
		double near, far, value1, value2;
		mCamera->getProjectionMatrixAsPerspective(value1,value2,near,far);
		OSG_NOTICE << "Near:"<< near<<",\t"<< "Far:"<< far << std::endl;
		osg::Vec4f v1= osg::Vec4f(near,far,value1,value2);
		uniform->set(v1);
		m_bFirstTime = false;
	}
}